package dfbz.线程唤醒;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class shower {
    private Condition c1;
    private Condition c2;
    private Condition c3;
    ReentrantLock lock=new ReentrantLock();
    private Integer flag=1;
    public shower() {
         c1 = lock.newCondition();
         c2 = lock.newCondition();
         c3 = lock.newCondition();
    }

    private void shower1() throws InterruptedException {
        lock.lock();
        while (flag!=1){
            c1.await();
        }
        System.out.print("我");
        System.out.print("爱");
        System.out.print("你");
        System.out.println();
        lock.unlock();
        flag=2;
        c2.signal();
    }
    private void shower2() throws InterruptedException {
        lock.lock();
        while (flag!=2){
            c2.await();
        }
        System.out.print("大");
        System.out.print("傻");
        System.out.print("逼");
        System.out.println();
        lock.unlock();
        flag=3;
        c3.signal();
    }
    private void shower3() throws InterruptedException {
        lock.lock();
        while (flag!=3){
            c3.await();
        }
        System.out.print("你");
        System.out.print("去");
        System.out.print("死");
        System.out.print("吧");
        System.out.println();
        lock.unlock();
        flag=1;
        c1.signal();
    }
}
